package com.meevle.view.components.visualization
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Graphics;
	import flash.events.Event;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.BlurFilter;
	import flash.media.SoundMixer;
	import flash.utils.ByteArray;
	
	public class CrossWaveformVisualization extends BaseVisualization
	{
		public var lColor:uint = 0x00FF00;
		public var rColor:uint = 0xFF0000;
		private var current : Number = 0;
		protected var hInterval : Number = 0;
		protected var vInterval : Number = 0;
		private var heightInterval : uint = 0;
		
		override protected function updateDisplayList(w:Number, h:Number):void {
			super.updateDisplayList(w, h);
			hInterval = w/256;
			vInterval = Math.floor( h/2 );
			
		}
		
		override protected function drawVisualization( e : Event ) : void
		{
			if( !this.visible ) return;      
			SoundMixer.computeSpectrum(spectrum, false);
			
			var g : Graphics = this.graphics;
			var i:uint
			g.clear();
			g.endFill();
			          	
			g.moveTo(0, vInterval);
			g.lineStyle( 1, lColor, 1);
			//left channel
			for (i = 0; i < 256 ; i++) {
				current = spectrum.readFloat();
				g.lineTo( (i*hInterval) , vInterval + (vInterval * current) );
			}
			 
			var tmpH : Number = hInterval; 
			var tmpV : Number = vInterval;
			
			hInterval = width/2;
			vInterval = height/256;
			           	
			g.moveTo(hInterval, 0);
			g.lineStyle( 1, rColor, 1);
			//right channel
			for (i = 0; i < 256 ; i++) {
				current = spectrum.readFloat();
				g.lineTo( hInterval+(current*hInterval) , (vInterval * i) );
			}
			
			hInterval = tmpH;
			vInterval = tmpV;
		}
		
	}
}